package com.hula.loan4u.adapter;


import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.hula.loan4u.R;
import com.hula.loan4u.base.MBaseLoopPagerAdapter;
import com.hula.loan4u.bean.BannerBean;
import com.hula.loan4u.cons.UmengKey;
import com.hula.loan4u.utils.AppUtils;
import com.hula.loan4u.utils.ImageLoaderUtil;
import com.hula.loan4u.utils.UmengUtil;

import java.util.HashMap;
import java.util.Map;


public class HomeBannerAdapter extends MBaseLoopPagerAdapter<BannerBean> {
    public HomeBannerAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position) {
        ImageView view = new ImageView(mContext);
        view.setScaleType(ImageView.ScaleType.FIT_XY);
        final BannerBean bean = getItem(position);
//        ImageLoaderUtil.showImage(view, AppCons.IMAGE_HOST + bean.imgUrl + AppUtils.getQiNiuParam(500, 250), R.drawable.image_default);
        ImageLoaderUtil.showImage(view, bean.imgUrl, R.drawable.image_default);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!TextUtils.isEmpty(bean.contentUrl)) {
                    Map<String, String> umengData = new HashMap<>();
                    umengData.put(bean.title, bean.contentUrl);
                    UmengUtil.onEvent(mContext, UmengKey.home_banner, umengData);

                    AppUtils.openBrowser(mContext, bean.contentUrl, null);
                }
            }
        });
        return view;
    }
}
